load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_doc")

package(default_visibility = ["//visibility:public"])

rust_binary(
    name = "hello_world_transient",
    srcs = ["src/main.rs"],
    deps = [
        "@crates//:anyhow",
    ],
)

rust_binary(
    name = "hello_world_vendored",
    srcs = ["src/main.rs"],
    deps = [
        "//third-party/crates:anyhow",
    ],
)

[
    rust_doc(
        name = "hello_world_{}_doc".format(target),
        crate = ":hello_world_{}".format(target),
    )
    for target in [
        "transient",
        "vendored",
    ]
]

[
    sh_test(
        name = "hello_world_{}_test".format(target),
        srcs = ["hello_world_test.sh"],
        args = [
            "$(rlocationpath :hello_world_{})".format(target),
        ],
        data = [
            ":hello_world_{}".format(target),
        ],
        deps = [
            "@bazel_tools//tools/bash/runfiles",
        ],
    )
    for target in [
        "transient",
        "vendored",
    ]
]

build_test(
    name = "gen_rust_project",
    targets = [
        "@rules_rust//tools/rust_analyzer:gen_rust_project",
    ],
)

build_test(
    name = "rust_fmt",
    targets = [
        "@rules_rust//:rustfmt",
    ],
)
